﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Dare.Utilities.Media
{
    public class FFmpegHelper
    {
        public static double av_q2d(FFmpeg.AVRational a)
        {
            return a.num / (double)a.den;
        }

        /// <summary>
        /// 获得视频帧率
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="codec"></param>
        /// <returns></returns>
        public static double GetFrameRate(FFmpeg.AVStream stream, FFmpeg.AVCodecContext codec)
        {
            if (stream.r_frame_rate.den > 0 && stream.r_frame_rate.num > 0)
            {
                return av_q2d(stream.r_frame_rate);
            }
            else
            {
                return 1 / av_q2d(codec.time_base);
            }
        }
    }
}
